package com.hz.friends.activity;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

public class SelectLanguageActivity extends BaseActivity{
	private ListView mlistview;
	private MyAdpter adpter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_selectlanguage);
		initViews();
		initEvents();
	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void initViews() {

		ImageButton imbtn_bar_left = (ImageButton) findViewById(R.id.imbtn_bar_left);
		ImageButton imbtn_bar_right = (ImageButton) findViewById(R.id.imbtn_bar_right);
		TextView imbtn_bar_title = (TextView) findViewById(R.id.imbtn_bar_title);
		imbtn_bar_right.setVisibility(View.INVISIBLE);
		imbtn_bar_left.setImageResource(R.drawable.ic_leftback_arrow);
		imbtn_bar_title.setText("language");
		imbtn_bar_left.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
               finish();				
			}
		});
		
		
		 mlistview = (ListView) findViewById(R.id.mlistview);
		 
		  adpter = new MyAdpter();
		 mlistview.setAdapter( adpter);
	}

	@Override
	protected void setViews() {
 
	}

	@Override
	protected void initEvents() {
		mlistview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				String text = adpter.getItem(position);
				Intent intent = new Intent();
				intent.putExtra("text", text);
				intent.putExtra("ischange", true);
				setResult(0, intent);
				finish();
			}
		});
	}
  
	class MyAdpter extends BaseAdapter{
		
		private String[] languages  = {"English","中文(简体)"};

		@Override
		public int getCount() {
			return languages.length;
		}

		@Override
		public String getItem(int position) {
			return languages[position];
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View view = LayoutInflater.from(SelectLanguageActivity.this).inflate(R.layout.adpter_selectlanguage, null);
			TextView  mtextview = (TextView) view.findViewById(R.id.mtextview);
			mtextview.setText(languages[position]);
 			return view;
		}
		
	}
}
